package com.baosight.sczx.zm.ca.service;

import java.util.Calendar;

import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.Utils;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.zm.ca.domain.VZMCA03;
import com.baosight.sczx.zm.ca.domain.ZMCA4101;
import com.baosight.sczx.zm.cp.domain.ZMCPProduceplandetailAll;
public class ServiceZMCA03 extends ServiceEPBase{
	/**
	 * 页面初始化，返回组织好的层级小代码
	 * 
	 * @param EiInfo
	 * @return EiInfo
	 */
	public EiInfo initLoad(EiInfo inInfo) {
		
		ZMCA4101 m4101 = new ZMCA4101();
		inInfo.addBlock(Utils.generateOutBlock("cmes.ca.config", m4101, inInfo, "ZMCA03.queryConfig", false));
		return inInfo;//return this.query(inInfo);
	}

	public EiInfo queryByIndex(EiInfo inInfo) {
		
		VZMCA03 m = new VZMCA03();
		Calendar currentTime = Calendar.getInstance(); 
		currentTime.add(Calendar.DATE, -1);
		int maxDay = currentTime.getActualMaximum(Calendar.DAY_OF_MONTH);
		
		//设置查询昨天计划量相关的参数
		StaticTools.setQueryParameters(inInfo, "fdMonthOfYesterday", currentTime.get(Calendar.MONTH)+1, true);
		StaticTools.setQueryParameters(inInfo, "fdDaysOfMonth", maxDay, true);
		String PlanType = inInfo.getString("PlanType");
		StaticTools.setQueryParameters(inInfo, "PlanType", PlanType, true);
		String IsDeploitation = inInfo.getString("IsDeploitation");
		StaticTools.setQueryParameters(inInfo, "IsDeploitation", IsDeploitation, true);
		
		EiInfo outInfo = super.query(inInfo, "ZMCA03.queryByIndex", m);	
		
		outInfo.set("dayOfYear", ""+(currentTime.get(Calendar.DAY_OF_YEAR)+1));
		outInfo.set("dayOfMonth", ""+(currentTime.get(Calendar.DAY_OF_MONTH)+1));
		inInfo.set("daysOfCurrentMonth", ""+maxDay);
		outInfo.set("year", ""+currentTime.get(Calendar.YEAR));
		
		return outInfo;
	}
	
	public EiInfo queryByChart(EiInfo inInfo) {
		VZMCA03 m = new VZMCA03();
		
		String PlanYear = inInfo.getString("PlanYear");
		StaticTools.setQueryParameters(inInfo, "PlanYear", PlanYear, true);
		String PlanType = inInfo.getString("PlanType");
		StaticTools.setQueryParameters(inInfo, "PlanType", PlanType, true);
		String IsDeploitation = inInfo.getString("IsDeploitation");
		StaticTools.setQueryParameters(inInfo, "IsDeploitation", IsDeploitation, true);
		inInfo.addBlock(Utils.generateOutBlock("queryByChart", m, inInfo, "ZMCA03.queryByChart", false));

		Calendar currentTime = Calendar.getInstance(); 
		inInfo.set("month", ""+(currentTime.get(Calendar.MONTH)+1));
		inInfo.set("year", ""+currentTime.get(Calendar.YEAR));
		return inInfo;
	}
	
	
	
	public EiInfo queryEngByChart(EiInfo inInfo) {
		VZMCA03 m = new VZMCA03();
		String projectType = inInfo.getDescName();
		StaticTools.setQueryParameters(inInfo, "fdType", projectType, true);
		StaticTools.setQueryParameters(inInfo, "fdPlanType", projectType, true);
		inInfo.addBlock(Utils.generateOutBlock("result", m, inInfo, "ZMCA03.queryEngByChart", false));

		inInfo.setDescName(projectType);
		Calendar currentTime = Calendar.getInstance(); 
		inInfo.set("month", ""+(currentTime.get(Calendar.MONTH)+1));
		inInfo.set("year", ""+currentTime.get(Calendar.YEAR));
		return inInfo;
	}
	
	
	
	public EiInfo queryByListView(EiInfo inInfo) {
		VZMCA03 m = new VZMCA03();
		String PlanType = inInfo.getString("PlanType");
		StaticTools.setQueryParameters(inInfo, "PlanType", PlanType, true);
		String IsDeploitation = inInfo.getString("IsDeploitation");
		StaticTools.setQueryParameters(inInfo, "IsDeploitation", IsDeploitation, true);
		
		inInfo.addBlock(Utils.generateOutBlock("queryByDepartment", m, inInfo, "ZMCA03.queryByDepartment", false));
		inInfo.addBlock(Utils.generateOutBlock("queryByDepartmentA", m, inInfo, "ZMCA03.queryByDepartmentA", false));
		if(PlanType.equals("采煤计划"))
		{
			inInfo.addBlock(Utils.generateOutBlock("queryByWorkFace", m, inInfo, "ZMCA03.queryByWorkFace", false));
			inInfo.addBlock(Utils.generateOutBlock("queryByWorkFaceA", m, inInfo, "ZMCA03.queryByWorkFaceA", false));
		}
		else 
		{
			//inInfo.addBlock(Utils.generateOutBlock("queryByRoadWay", m, inInfo, "ZMCA03.queryByRoadWay", false));
			//inInfo.addBlock(Utils.generateOutBlock("queryByRoadWayA", m, inInfo, "ZMCA03.queryByRoadWayA", false));
			inInfo.addBlock(Utils.generateOutBlock("queryByMineRock", m, inInfo, "ZMCA03.queryByMineRock", false));
			inInfo.addBlock(Utils.generateOutBlock("queryByMineRockA", m, inInfo, "ZMCA03.queryByMineRockA", false));
			if(IsDeploitation.trim().length()<=0)
			{
				//inInfo.addBlock(Utils.generateOutBlock("queryByRoadWayUsing", m, inInfo, "ZMCA03.queryByRoadWayUsing", false));
				//inInfo.addBlock(Utils.generateOutBlock("queryByRoadWayUsingA", m, inInfo, "ZMCA03.queryByRoadWayUsingA", false));
				inInfo.addBlock(Utils.generateOutBlock("ProjectClass", m, inInfo, "ZMCA03.queryByProjectClass", false));
			}
		}


		Calendar currentTime = Calendar.getInstance(); 
		inInfo.set("month", ""+(currentTime.get(Calendar.MONTH)+1));
		inInfo.set("year", ""+currentTime.get(Calendar.YEAR));
		return inInfo;
	}
	
	/**
	 * 
	 * <p>Function: queryProducePlanDetail</p>
	 * <p>Description: </p>
	 * <p>return value: EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-07-12 15:03:26 高平
	 * </p>
	 *
	 */
	public EiInfo queryProducePlanDetail(EiInfo inInfo) {
		String fdYear = inInfo.getString("fdYear");
		String fdMonth = inInfo.getString("fdMonth");
		String fdPlanType = inInfo.getString("fdPlanType");
		StaticTools.setQueryParameters(inInfo, "fdYear", fdYear, true);
		StaticTools.setQueryParameters(inInfo, "fdMonth", fdMonth, true);
		StaticTools.setQueryParameters(inInfo, "fdPlanType", fdPlanType, true);
		inInfo.addBlock(Utils.generateOutBlock("result", new ZMCPProduceplandetailAll(), inInfo, "ZMCA03.queryProducePlanDetail", false));
		//EiInfo outInfo = super.query(inInfo, "ZMCPProduceplandetailAll.query", new ZMCPProduceplandetailAll());

		return inInfo;
	}
	
	public EiInfo queryOtherProjectCount(EiInfo inInfo) {
		String fdYear = inInfo.getString("fdYear");
		StaticTools.setQueryParameters(inInfo, "fdYear", fdYear, true);
		inInfo.addBlock(Utils.generateOutBlock("result", new VZMCA03(), inInfo, "ZMCA03.queryOtherProjectCount", false));
		//EiInfo outInfo = super.query(inInfo, "ZMCPProduceplandetailAll.query", new ZMCPProduceplandetailAll());

		return inInfo;
	}
	
	public EiInfo queryProjectOutput(EiInfo inInfo) {
		VZMCA03 m = new VZMCA03();		
		String projectType = inInfo.getDescName();
		StaticTools.setQueryParameters(inInfo, "fdType", projectType, true);
		StaticTools.setQueryParameters(inInfo, "fdPlanType", projectType, true);
		inInfo.addBlock(Utils.generateOutBlock("result", m, inInfo, "ZMCA03.queryEngByChart", false));
		inInfo.setDescName(projectType);
		return inInfo;
	}
	
	public EiInfo queryByCurveChart(EiInfo inInfo)
	{
		VZMCA03 m = new VZMCA03();
		inInfo.addBlock(Utils.generateOutBlock("queryBlock", m, inInfo, "ZMCA03.queryByCurveChart", false));
		
		return inInfo;
	}
	
	public EiInfo queryByDayChart(EiInfo inInfo)
	{		
		VZMCA03 m = new VZMCA03();
		Calendar currentTime = Calendar.getInstance(); 
		int maxDay = currentTime.getActualMaximum(Calendar.DAY_OF_MONTH);
		StaticTools.setQueryParameters(inInfo, "fdDaysOfMonth", maxDay, true);
		inInfo.addBlock(Utils.generateOutBlock("queryPlanDayMine", m, inInfo, "ZMCA03.queryPlanByDayChart", false));
		
		inInfo.set("daysOfCurrentMonth", ""+maxDay);
		inInfo.set("year", ""+currentTime.get(Calendar.YEAR));
		inInfo.set("month", ""+currentTime.get(Calendar.MONTH));
		inInfo.set("day", ""+currentTime.get(Calendar.DAY_OF_MONTH));
		
		inInfo.addBlock(Utils.generateOutBlock("queryActualDayMine", m, inInfo, "ZMCA03.queryActualByDayChart", false));
		return inInfo;
	}
	
	public EiInfo queryByDayGrubChart(EiInfo inInfo)
	{
		VZMCA03 m = new VZMCA03();
		Calendar currentTime = Calendar.getInstance(); 
		int maxDay = currentTime.getActualMaximum(Calendar.DAY_OF_MONTH);
		StaticTools.setQueryParameters(inInfo, "fdDaysOfMonth", maxDay, true);
		inInfo.addBlock(Utils.generateOutBlock("queryPlanDayGrub", m, inInfo, "ZMCA03.queryPlanByDayGrubChart", false));
		
		inInfo.set("daysOfCurrentMonth", ""+maxDay);
		inInfo.set("year", ""+currentTime.get(Calendar.YEAR));
		inInfo.set("month", ""+currentTime.get(Calendar.MONTH));
		inInfo.set("day", ""+currentTime.get(Calendar.DAY_OF_MONTH));
		
		inInfo.addBlock(Utils.generateOutBlock("queryActualDayGrub", m, inInfo, "ZMCA03.queryActualByDayGrubChart", false));
		return inInfo;
	}
	
	public EiInfo queryByDeploitChartCurrentMonth(EiInfo inInfo)
	{
		VZMCA03 m = new VZMCA03();
		inInfo.addBlock(Utils.generateOutBlock("queryBlock", m, inInfo, "ZMCA03.queryByDeploitChartCurrentMonth", false));
		
		return inInfo;
	}
}
